package com.example.consumer;

import com.example.common.model.User;
import com.example.common.service.UserService;
import com.example.easyrpc.config.RpcConfig;
import com.example.easyrpc.proxy.ServiceProxyFactory;
import com.example.easyrpc.utils.ConfigUtils;

/**
 * 简易的服务消费者案例
 */
public class EasyConsumerExample {

    public static void main(String[] args) {
        RpcConfig rpcConfig = ConfigUtils.loadConfig(RpcConfig.class, "rpc");
        System.out.println(rpcConfig);
        // 动态代理
        UserService userService = ServiceProxyFactory.getProxy(UserService.class);
        User user = new User();
        user.setName("张三");
        //调用
        User newUser = userService.getUser(user);
        if (newUser != null) {
            System.out.println("用户名:" + newUser.getName());
        } else {
            System.out.println("用户不存在");
        }
    }
}
